﻿@model List<WebEntities.Models.WebInfo.LeaveMsg>

@{
    ViewBag.Title = "网站管理平台_留言管理视图";
}

@section HeadContent
{
    <script src="/Scripts/LeaveMsg/index.js" type="text/javascript"></script>
}

@(Html.X().Menu()
    .ID("Grid1CtxMenu")
    .Items(
        Html.X().MenuItem().Text("查看留言").Icon(Icon.BookEdit)
            .DirectEvents(de =>
            {
                de.Click.Action = "EditMsgWindow";
                de.Click.ExtraParams.Add(new Parameter("msgId", "this.parentMenu.dataRecord.data.MsgID", ParameterMode.Raw));
            }),
        Html.X().MenuItem().Text("删除留言").Icon(Icon.Cross).Listeners(ls => ls.Click.Handler = "App.BtnDeleteSel.getEl().dom.click()")
    )
)

@Html.X().Hidden().ID("DeleteHint").Text("是否要删除选中的用户留言以及它的回复信息吗？")

@(Html.X().Viewport()
    .Layout(LayoutType.Border)
    .Items(
        Html.X().Panel()
            .Region(Region.West)
            .Width(200)
            .Title("留言类别列表")
            .Collapsible(true)
            .Split(true)
            .MinWidth(150)
            .MaxWidth(300)
            .Layout(LayoutType.Fit)
            .Items(
                Html.X().GridPanel().ID("MsgTypeGrid")
                    .Store(
                        Html.X().Store()
                            .AutoSync(true)
                            .ShowWarningOnFailure(false)
                            .Proxy(proxy => proxy.Add(Html.X().AjaxProxy()
                                .Url(Url.Action("GetAllMsgType", "LeaveMsgType"))
                                .Reader(Html.X().JsonReader().Root("data").IDProperty("TypeID"))
                                .Writer(writer => new JsonWriter { AllowSingle = true, Root = "data" })
                                .API(api =>
                                {
                                    api.Destroy = Url.Action("DeleteMsgType", "LeaveMsgType");
                                    api.Update = Url.Action("UpdateMsgType", "LeaveMsgType");
                                })
                            ))
                            .Model(Html.X().Model().IDProperty("TypeID")
                                .Fields(
                                    new ModelField("TypeID", ModelFieldType.Int),
                                    new ModelField("MsgType")
                                )
                            )
                    )
                    .ColumnModel(
                        Html.X().Column().DataIndex("MsgType").Text("留言类别").Flex(1).MenuDisabled(true).Editor(Html.X().TextField())
                     )
                    .SelectionModel(Html.X().RowSelectionModel().Mode(SelectionMode.Multi))
                    .Plugins(
                        Html.X().CellEditing().Listeners(ls =>
                        {
                            ls.BeforeEdit.Fn = "beforeEditMsgType";
                        })
                    )
                    .Listeners(ls =>
                    {
                        ls.ItemClick.Fn = "changeMsgType";
                    })
                    .View(Html.X().GridView().StripeRows(true))
                    .TopBar(
                        Html.X().Toolbar()
                            .Items(
                                Html.X().Button().Text("新建类别").Icon(Icon.Add).DirectClickAction("NewMsgTypeWindow", "LeaveMsgType"),
                                Html.X().Button().ID("BtnDeleteMsgType").Text("删除类别").Icon(Icon.Cross)
                                    .Listeners(
                                        ls => ls.Click.Fn = "deleteMsgTypeGridSelected"
                                    )
                            )
                    )
            ),
        Html.X().Panel()
            .Region(Region.Center)
            .Title("用户留言列表")
            .Layout(LayoutType.Fit)
            .Items(
                Html.X().GridPanel()
                    .ID("GridPanel1")
                    .Store(
                        Html.X().StoreForModel()
                            .AutoSync(true)
                            .PageSize(50)
                            .ShowWarningOnFailure(false)
                            .Proxy(proxy => proxy.Add(Html.X().AjaxProxy()
                                .Url(Url.Action("GetAllLeaveMsgByPage"))
                                .ExtraParams(ep =>
                                {
                                    ep.Add(new Parameter("typeId", "0"));
                                })
                                .Reader(Html.X().JsonReader().Root("data"))
                                .Writer(writer => new JsonWriter { AllowSingle = true, Root = "data" })
                                .API(api => { api.Destroy = Url.Action("DeleteLeaveMsg"); })
                            ))
                            .Listeners(ls => ls.Write.Fn = "ext.net.comjs.onGridChange")
                    )
                    .ColumnModel(
                        Html.X().RowNumbererColumn(),
                        Html.X().Column().DataIndex(Model, m => m.MsgID).Text("留言ID"),
                        Html.X().Column().DataIndex(Model, m => m.TypeName).Text("留言类别"),
                        Html.X().Column().DataIndex(Model, m => m.MsgSubject).Text("标题"),
                        Html.X().DateColumn().DataIndex(Model, m => m.CreateTime).Text("创建时间").Format("yyyy-MM-dd HH:mm:ss").Width(120),
                        Html.X().BooleanColumn().DataIndex(Model, m => m.IsReply).Text("回复留言").FalseText("暂未回复").TrueText("已回复"),
                        Html.X().BooleanColumn().DataIndex(Model, m => m.IsPublic).Text("审核状态").FalseText("审核未通过").TrueText("已发布")
                     )
                    .SelectionModel(Html.X().CheckboxSelectionModel().Mode(SelectionMode.Multi))
                    .Listeners(ls =>
                    {
                        ls.ItemContextMenu.Handler = "e.preventDefault(); App.Grid1CtxMenu.dataRecord = this.store.getAt(index); App.Grid1CtxMenu.showAt(e.getXY());";
                    })
                    .View(Html.X().GridView().StripeRows(true))
                    .DirectEvents(de =>
                    {
                        de.ItemDblClick.Action = "EditMsgWindow";
                        de.ItemDblClick.ExtraParams.Add(new Parameter("msgId", "record.data['MsgID']", ParameterMode.Raw));
                    })
                    .TopBar(
                        Html.X().Toolbar()
                            .Items(
                                Html.X().Button().Text("留言审核").Icon(Icon.ScriptEdit)
                                    .Menu(mu => mu.Add(Html.X().Menu()
                                        .Items(
                                            Html.X().MenuItem().Text("审核通过").Icon(Icon.ScriptStart)
                                                .DirectEvents(de =>
                                                {
                                                    de.Click.Action = "BatchAuditLeaveMsg";
                                                    de.Click.ExtraParams.Add(new Parameter("leaveMsgs", "Ext.encode(#{GridPanel1}.getRowsValues({selectedOnly:true}))", ParameterMode.Raw));
                                                    de.Click.ExtraParams.Add(new Parameter("isPub", "true"));
                                                    de.Click.EventMask.ShowMask = true;
                                                    de.Click.EventMask.Msg = "正在提交审核结果";
                                                    de.Click.Success = "onAuditSuccess";
                                                    de.Click.Failure = "ext.net.comjs.onSubmitFailure";
                                                })
                                                .Listeners(ls =>
                                                {
                                                    ls.Click.Handler = "return this.up('grid').hasSelection();";
                                                }),
                                            Html.X().MenuItem().Text("审核不通过").Icon(Icon.ScriptStop)
                                                .DirectEvents(de =>
                                                {
                                                    de.Click.Action = "BatchAuditLeaveMsg";
                                                    de.Click.ExtraParams.Add(new Parameter("leaveMsgs", "Ext.encode(#{GridPanel1}.getRowsValues({selectedOnly:true}))", ParameterMode.Raw));
                                                    de.Click.ExtraParams.Add(new Parameter("isPub", "false"));
                                                    de.Click.EventMask.ShowMask = true;
                                                    de.Click.EventMask.Msg = "正在提交审核结果";
                                                    de.Click.Success = "onAuditSuccess";
                                                    de.Click.Failure = "ext.net.comjs.onSubmitFailure";
                                                })
                                                .Listeners(ls =>
                                                {
                                                    ls.Click.Handler = "return this.up('grid').hasSelection();";
                                                })
                                        ))
                                    ),
                                Html.X().Button().ID("BtnDeleteSel").Text("删除留言").Icon(Icon.Cross)
                                    .Listeners(
                                        ls => ls.Click.Fn = "ext.net.comjs.deleteGridSelected"
                                    )
                            )
                    )
                    .BottomBar(
                        Html.X().PagingToolbar()
                            .Items(
                                Html.X().Label("每页显示行数："),
                                Html.X().ToolbarSpacer(10),
                                Html.X().ComboBox()
                                    .Width(80)
                                    .Items("10", "50", "100")
                                    .SelectedItems("50")
                                    .Listeners(lr =>
                                    {
                                        lr.Select.Fn = "ext.net.comjs.onPageSizeChange";
                                    })
                            )
                    )
            )
    )
)